<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class home extends CI_Controller 
{
    function __construct(){
            parent::__construct();
            $this->load->helper('url');
            $this->load->model('entity_model');
            $this->load->library('session');
    }
    public function index()
    {
        //session dibuang semua jika kembali ke home.
       if($this->session->userdata('username'))
        {
            $this->session->unset_userdata('username');
        }
        $data['username'] = null;
//        if($this->session->userdata('username'))
//        {
//            $data['username'] = $this->session->userdata('username');
//        }
//        else
//        {
//            $data['username'] = null;
//        }
        
        $data['title'] = 'Logbook and Event Management Website';
        $data['subtitle'] = '';
        $this->load->view('_header',$data);
        $this->load->view('home_view',$data);
        $this->load->view('_footer',$data);
    }
    
    public function loginLB()
    {
        $username = $this->input->post('username_box');
        
        $password = $this->input->post('password_box');
        $cek = $this->entity_model->checkLoginLB($username,$password);
        
        if ($cek->num_rows()>0)
        {
            $status = "masuk";
            $this->session->set_userdata('username', $username);
            $this->session->set_userdata('tipemember',1);
        }
        else
        {
            $status ="Username dan Password tidak ditemukan";
        }
        echo json_encode(array('status_loginLB' => $status));
        
        exit;
       // redirect('');
    }
    
    public function loginEV()
    {
        $username = $this->input->post('username_box_ev');
        $password = $this->input->post('password_box_ev');
        
        $cek = $this->entity_model->checkLoginEV($username,$password);
        
        if ($cek->num_rows()>0)
        {
            $status = "masuk";
            $this->session->set_userdata('username', $username);
            $this->session->set_userdata('tipemember',2);
        }
        else
        {
            $status ="Username dan Password tidak ditemukan";
        }
        echo json_encode(array('status_loginEV' => $status));
        
        exit;
    }
    
    public function daftarLB()
    {
        $nama = $this->input->post('nama_box');
        $pass = $this->input->post('pass_box');
        
        if ($nama && $pass )
        {
            $status = $this->entity_model->daftarLB($nama,$pass);
        }
        else
        {
            $status = "Isi semua data !";
        }
        echo json_encode(array('status_daftar'=> $status));
        exit;
    }
    
    public function daftarEV()
    {
        $nama = $this->input->post('nama_box');
        $pass = $this->input->post('pass_box');
        $depar = $this->input->post('depar_box');
        
        if ($nama && $pass )
        {
            $status = $this->entity_model->daftarEV($nama,$pass,$depar);
        }
        else
        {
            $status = "Isi semua data !";
        }
        echo json_encode(array('status_daftar'=> $status));
        exit;
    }

     public function logout(){
            //$this->session->sess_destroy();
            $this->session->unset_userdata('username');
            redirect(base_url());
    }
}

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
?>
